package com.cx.controller;

import com.cx.pojo.Order;
import com.cx.pojo.User;
import com.cx.service.impl.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.List;

/**
 * @Description GroupOneproject-IntelliJ IDEA
 * @Author Pyc
 * @Date 2020/5/4 13:32
 * @Version 1.0
 */

@Controller
public class MainController {
    private List<String> htmls = new ArrayList<>();
    @Autowired
    Service service;

    @RequestMapping("/")
    public String index(){
        return "index";
    }

    @RequestMapping("/login")
    public String toLogin(){
        return "login";
    }

    @RequestMapping("/regist")
    public String toRegist(){
        return "regist";
    }

    @RequestMapping("/iforget")
    public String iForget(){
        return "forget";
    }

    @RequestMapping("/logout")
    public String logOut(HttpSession session){
        service.deleteUser();
        session.removeAttribute("user");
        return "jump";
    }
    @RequestMapping("server")
    @ResponseBody
    public User test(@RequestBody User userInfo){
        System.out.println("成功访问到这个页面");
        return userInfo;
    }
    @RequestMapping(value = "recentHtml",produces = "application/json;charset=utf-8")
    @ResponseBody
    public void recentHtml(@RequestBody List<String> htmlPage){
        if(htmls.size() != 0){
            htmls.remove(0);//清空htmls
        }
        htmls.add(htmlPage.get(0));//将传入的网页装载进去
    }
    @ResponseBody
    @RequestMapping("getRecentHtml")
    public String getRecentHtmls(){
        if(htmls.size() > 0){
            return htmls.get(0);
        }
        return null;
    }


    @RequestMapping("getOrderInfo")
    @ResponseBody
    public List<Order> getOrderInfoZCJ(String userName){
        System.out.println(userName + "男女男");
        return service.getOrderInfoByUserName(userName);
    }
}
